function main_basicfeature(G,pid,sid,INDIR,OUTDIR)
%% Load Data (Formatted Raw, Formatted Data)
fprintf('%-6s %-6s %-20s Task (',pid,sid,'main_basicfeature');
indir=[G.DIR.DATA G.DIR.SEP INDIR];
infile=[pid '_' sid '_' G.FILE.FRMTDATA_MATNAME];
outdir=[G.DIR.DATA G.DIR.SEP OUTDIR];
outfile=[pid '_' sid '_' G.FILE.BASICFEATURE_MATNAME];

if isempty([indir G.DIR.SEP infile]),    disp(['FILE NOT FOUND' indir G.DIR.SEP infile]);return;end
load([indir G.DIR.SEP infile]);
if isempty(dir([outdir G.DIR.SEP outfile])) || G.RUN.BASICFEATURE.LOADDATA==0, B=D;
else load([outdir G.DIR.SEP outfile]);end
for i=1:length(B.sensor)
    if isfield(B.sensor{i},'matlabtime_all'), B.sensor{i}=rmfield(B.sensor{i},'matlabtime_all');end
    if isfield(B.sensor{i},'timestamp_all'), B.sensor{i}=rmfield(B.sensor{i},'timestamp_all');end
    if isfield(B.sensor{i},'sample_all'), B.sensor{i}=rmfield(B.sensor{i},'sample_all');end
end

B.NAME=['BASICFEATURE[' G.STUDYNAME ' ' pid ' ' sid ']'];
if G.RUN.BASICFEATURE.PEAKVALLEY, B.sensor{G.FEATURE.R_RIPID}.peakvalley=main_basicfeature_rip(G,D.sensor{G.SENSOR.R_RIPID}.sample,D.sensor{G.SENSOR.R_RIPID}.timestamp);end
if G.RUN.BASICFEATURE.RR, B.sensor{G.FEATURE.R_ECGID}.rr=main_basicfeature_ecg(G,D.sensor{G.SENSOR.R_ECGID}.sample,D.sensor{G.SENSOR.R_ECGID}.timestamp);end

%% Save Data
if isempty(dir(outdir))
    mkdir(outdir);
end
save([outdir G.DIR.SEP outfile],'B');
fprintf(') =>  done\n');

end

